<template>
    <div>
        <el-page-header>
            <template #breadcrumb>
                <el-breadcrumb separator="/">
                    <el-breadcrumb-item :to="{ path: 'adminhome' }">
                        管理员主页
                    </el-breadcrumb-item>
                    <el-breadcrumb-item>企业管理</el-breadcrumb-item>
                </el-breadcrumb>
            </template>
        </el-page-header>
    </div><br />
    <el-table :data="tableData" style="width: 100%" height="300">
        <el-table-column fixed prop="companyId" label="企业编号" min-width="100" />
        <el-table-column prop="companyName" label="名称" min-width="100" :formatter="formatDate" />
        <el-table-column prop="companyInfo" label="企业详情" min-width="100" />
        <el-table-column prop="companyPhone" label="联系电话" min-width="100" />
        <el-table-column prop="companyTrade" label="行业" min-width="100" />
        <el-table-column fixed="right" label="操作" width="120">
            <template #default="scope">
                <el-button link type="primary" size="small" @click="aaa(scope.row.companyId)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-divider content-position="left">添加企业</el-divider>
    <div style="display: flex; justify-content: center;text-align: center; width: 100%;">
        <el-form :label-position="right" label-width="100px" :model="formLabelAlign" style="width: 60%">
            <el-form-item label="企业名：" size="large">
                <el-input v-model="aaaa.companyName" />
            </el-form-item>
            <el-form-item label="企业详情：" size="large">
                <el-input v-model="aaaa.companyInfo" type="textarea" />
            </el-form-item>
            <el-form-item label="联系电话：" size="large">
                <el-input v-model="aaaa.companyPhone" />
            </el-form-item>
            <el-form-item label="行业：" size="large">
                <el-input v-model="aaaa.companyTrade" />
            </el-form-item>
            <el-form-item label="密码：" size="large">
                <el-input v-model="aaaa.companyPassword" />
            </el-form-item>
            <el-form-item size="large">
                <el-button type="info" style="height: 50px; width: 100px;" @click="updata">添加企业</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
import { ref, onBeforeMount, toRefs, onBeforeUnmount, reactive } from 'vue'
import requests from '@/api/ajax.js'

const tableData = ref([{
    companyId: '',
    companyName: '',
    companyInfo: '',
    companyPhone: '',
    companyTrade: '',
    companyPassword: '',
}])
onBeforeMount(() => {

    //请求学生信息
    const aacom = requests({ url: "/company/allCompany", method: "get", }).then(res => {
        //存储信息到浏览器toke
        const abc = res.rdata
        tableData.value = abc
        console.log(res)
    })
        .catch(err => {
            console.error(err.data);
            // 登录请求失败后的操作
        });
})

function updata() {
    const acd = requests({ url: "/excel/addCompany", method: "post", data: aaaa.value }).then(res => {

        if (res.code == 20041) {
            alert(res.msg)
            const asd = requests({ url: "/company/allCompany", method: "get", }).then(res => {
                //存储用户信息到浏览器toke
                tableData.value = res.rdata
            })
                .catch(err => {
                    console.error(err.data);
                   
                });
        } else if (res.code === 20040) {
            alert(res.msg)
        } else {
            alert('发生错误，请查看服务器问题')
        }
    })
        .catch(err => {
            console.error(err.data);
            // 登录请求失败后的操作
        })

}
const aaaa = ref({

})

function aaa(companyId) {
    const asd = requests({ url: "/excel/deleteCompany/" + companyId, method: "get", }).then(res => {
        if (res.code === 20021) {
            alert(res.msg)
            const asd = requests({ url: "/company/allCompany", method: "get", }).then(res => {
                //存储用户信息到浏览器toke
                tableData.value = res.rdata
            })
                .catch(err => {
                    console.error(err.data);
                    // 登录请求失败后的操作
                });
        } else if (res.code === 20020) {
            alert(res.msg)
        } else {
            alert('发生错误，请查看服务器问题')
        }
    })
        .catch(err => {
            console.error(err.data);
            // 登录请求失败后的操作
        });
}
</script>